package queue_stack.leetcode.medium;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @author bruin_du
 * @description 数据流的第 K 大数值
 * @date 2022/8/16 21:59
 **/
public class OfferII059_KthLargest {
    Queue<Integer> queue;
    int k;

    public OfferII059_KthLargest(int k, int[] nums) {
        queue = new PriorityQueue<>();
        this.k = k;
        for (int x : nums) {
            add(x);
        }
    }

    public int add(int val) {
        queue.offer(val);
        if (queue.size() > k) {
            queue.poll();
        }
        return queue.peek();
    }
}
